local shenwu = fk.CreateSkill {
  name = "lingling__shenwu",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["lingling__shenwu"] = "神武",
  [":lingling__shenwu"] = "锁定技，当你使用属性杀后，你随机获得一张锦囊牌。当你使用伤害类锦囊牌后，你随机获得一张装备牌。"..
  "当你使用武器牌后，你随机获得一张【杀】（本回合使用无次数限制）。回合结束时，若你以上三种牌均未使用，你随机获得其中一张。",

  ["@@lingling__shenwu-inhand-turn"] = "神武",
}

local shenwuCheck = function (card)
  return (card.trueName == "slash" and card.name ~= "slash") or
    (card.is_damage_card and card.type == Card.TypeTrick) or
    card.sub_type == Card.SubtypeWeapon
end

shenwu:addEffect(fk.CardUseFinished, {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(shenwu.name) and shenwuCheck(data.card)
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local card = {}
    if data.card.trueName == "slash" and data.card.name ~= "slash" then
      card = room:getCardsFromPileByRule(".|.|.|.|.|trick", 1, "allPiles")
    elseif data.card.is_damage_card and data.card.type == Card.TypeTrick then
      card = room:getCardsFromPileByRule(".|.|.|.|.|equip", 1, "allPiles")
    else
      card = room:getCardsFromPileByRule("slash", 1, "allPiles")
    end
    if #card > 0 then
      local moveMark = Fk:getCardById(card[1]).trueName == "slash" and "@@lingling__shenwu-inhand-turn" or nil
      room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonJustMove, shenwu.name, nil, true, player, moveMark)
    end
  end,
})

shenwu:addEffect(fk.TurnEnd, {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(shenwu.name) and
      #player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
        local use = e.data
        return use.from == player and shenwuCheck(use.card)
      end, Player.HistoryTurn) == 0
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local card = {}
    for _, id in ipairs(table.connect(room.draw_pile, room.discard_pile)) do
      if shenwuCheck(Fk:getCardById(id)) then
        table.insert(card, id)
      end
    end
    if #card > 0 then
      card = table.random(card, 1)
    end
    if #card > 0 then
      local moveMark = Fk:getCardById(card[1]).trueName == "slash" and "@@lingling__shenwu-inhand-turn" or nil
      room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonJustMove, self.name, nil, true, player.id, moveMark)
    end
  end,
})

shenwu:addEffect(fk.PreCardUse, {
  can_refresh = function (self, event, target, player, data)
    return target == player and data.card.trueName == "slash" and
      data.card:getMark("@@lingling__shenwu-inhand-turn") > 0
  end,
  on_refresh = function (self, event, target, player, data)
    data.extraUse = true
  end,
})

shenwu:addEffect("targetmod", {
  bypass_times = function (self, player, skill, scope, card)
    return card:getMark("@@lingling__shenwu-inhand-turn") > 0
  end,
})

return shenwu
